<!DOCTYPE html>
<html>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>登录</title>
    <meta charset="utf-8"/>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/semantic/semantic.min.css}"/>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css">
</head>
<style>
    body {
        background-color: #0e8c8c;
    }

    #login {
        text-align: center;
        background-color: #0e566c;
        width: 400px;
        height: 300px;
        margin: auto;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
</style>
<body>

<div class="container">
    <div id="login">
        <div style="margin-left: -20px;margin-top: 60px;margin-right: 20px">
            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">账号</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" style="margin-left: -115px">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">登录</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript" th:src="@{/js/jquery-3.4.1.min.js}"></script>
<script type="text/javascript" th:src="@{/semantic/semantic.min.js}"></script>
<script type="text/javascript" th:src="@{/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/js/upload.js}"></script>
<script>
    function error() {
        layui.use('layer', function () {
            let layer = layui.layer;
            layer.alert('账号或密码错误！', {
                skin: 'layui-layer-lan' //样式类名
                , closeBtn: 0,
                anim: 6
            });
        });
    }

    layui.use(['form'], function () {
        let form = layui.form;
        //监听提交
        form.on('submit(demo1)', function (data) {
            $.ajax({
                url: "/login/doLogin",
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(data.field),
                success: function (data) {
                    if (data.msg === 'SUCCESS') {
                        switch (data.result) {
                            //员工信息
                            case 0:
                            case 1:
                                window.location.href = "/staff";
                                break
                            //前台管理
                            case 2:
                                window.location.href = "/staff_head";
                                break
                            //主管页面
                            case 3:
                                window.location.href = "/master";
                                break
                            //管理员（老板）页面
                            case 4:
                                window.location.href = "/admin";
                                break
                        }
                    } else {
                        error();
                    }
                }
            });
            return false;
        });
    })
</script>
</body>
</html>
